<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="订单编号" prop="orderNum">
      <el-input v-model="dataForm.orderNum" placeholder="订单编号"></el-input>
    </el-form-item>
    <el-form-item label="用户id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
    </el-form-item>
    <el-form-item label="商品id" prop="goodId">
      <el-input v-model="dataForm.goodId" placeholder="商品id"></el-input>
    </el-form-item>
    <el-form-item label="商品数量" prop="goodQuantity">
      <el-input v-model="dataForm.goodQuantity" placeholder="商品数量"></el-input>
    </el-form-item>
    <el-form-item label="总金额" prop="aggregateAmount">
      <el-input v-model="dataForm.aggregateAmount" placeholder="总金额"></el-input>
    </el-form-item>
    <el-form-item label="实际支付" prop="actuallyPaid">
      <el-input v-model="dataForm.actuallyPaid" placeholder="实际支付"></el-input>
    </el-form-item>
    <el-form-item label="下单时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="下单时间"></el-input>
    </el-form-item>
    <el-form-item label="订单状态(1等待付款 2申请退款 3退款成功 4交易成功)" prop="orderStatus">
      <el-input v-model="dataForm.orderStatus" placeholder="订单状态(1等待付款 2申请退款 3退款成功 4交易成功)"></el-input>
    </el-form-item>
    <el-form-item label="支付状态(1已支付 2未支付)" prop="payStatus">
      <el-input v-model="dataForm.payStatus" placeholder="支付状态(1已支付 2未支付)"></el-input>
    </el-form-item>
    <el-form-item label="发货状态(1未发货 2已发货)" prop="shippingStatus">
      <el-input v-model="dataForm.shippingStatus" placeholder="发货状态(1未发货 2已发货)"></el-input>
    </el-form-item>
    <el-form-item label="收货状态(1未收货 2已收货)" prop="receivingAForm">
      <el-input v-model="dataForm.receivingAForm" placeholder="收货状态(1未收货 2已收货)"></el-input>
    </el-form-item>
    <el-form-item label="发货备注" prop="remarkDesc">
      <el-input v-model="dataForm.remarkDesc" placeholder="发货备注"></el-input>
    </el-form-item>
    <el-form-item label="快递单号" prop="logisticsInformationId">
      <el-input v-model="dataForm.logisticsInformationId" placeholder="快递单号"></el-input>
    </el-form-item>
    <el-form-item label="物流公司" prop="logisticsInformation">
      <el-input v-model="dataForm.logisticsInformation" placeholder="物流公司"></el-input>
    </el-form-item>
    <el-form-item label="" prop="
exemptionFromPostageStatus">
      <el-input v-model="dataForm.
exemptionFromPostageStatus" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="a">
      <el-input v-model="dataForm.a" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="b">
      <el-input v-model="dataForm.b" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="c">
      <el-input v-model="dataForm.c" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
          baseURL: 'http://localhost:7001',
        visible: false,
        dataForm: {
          id: 0,
          orderNum: '',
          userId: '',
          goodId: '',
          goodQuantity: '',
          aggregateAmount: '',
          actuallyPaid: '',
          createTime: '',
          orderStatus: '',
          payStatus: '',
          shippingStatus: '',
          receivingAForm: '',
          remarkDesc: '',
          logisticsInformationId: '',
          logisticsInformation: '',
          
exemptionFromPostageStatus: '',
          a: '',
          b: '',
          c: ''
        },
        dataRule: {
          orderNum: [
            { required: true, message: '订单编号不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '用户id不能为空', trigger: 'blur' }
          ],
          goodId: [
            { required: true, message: '商品id不能为空', trigger: 'blur' }
          ],
          goodQuantity: [
            { required: true, message: '商品数量不能为空', trigger: 'blur' }
          ],
          aggregateAmount: [
            { required: true, message: '总金额不能为空', trigger: 'blur' }
          ],
          actuallyPaid: [
            { required: true, message: '实际支付不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '下单时间不能为空', trigger: 'blur' }
          ],
          orderStatus: [
            { required: true, message: '订单状态(1等待付款 2申请退款 3退款成功 4交易成功)不能为空', trigger: 'blur' }
          ],
          payStatus: [
            { required: true, message: '支付状态(1已支付 2未支付)不能为空', trigger: 'blur' }
          ],
          shippingStatus: [
            { required: true, message: '发货状态(1未发货 2已发货)不能为空', trigger: 'blur' }
          ],
          receivingAForm: [
            { required: true, message: '收货状态(1未收货 2已收货)不能为空', trigger: 'blur' }
          ],
          remarkDesc: [
            { required: true, message: '发货备注不能为空', trigger: 'blur' }
          ],
          logisticsInformationId: [
            { required: true, message: '快递单号不能为空', trigger: 'blur' }
          ],
          logisticsInformation: [
            { required: true, message: '物流公司不能为空', trigger: 'blur' }
          ],
          
exemptionFromPostageStatus: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          a: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          b: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          c: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
              axios({
              url: `${this.baseURL}/hospital_goods/orderlist/info/${this.dataForm.id}`,
              method: 'get',
              params: '',
              // `responseType` 表示浏览器将要响应的数据类型
              // 选项包括: 'arraybuffer', 'document', 'json', 'text', 'stream'
              responseType: 'json'
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.orderNum = data.orderList.orderNum
                this.dataForm.userId = data.orderList.userId
                this.dataForm.goodId = data.orderList.goodId
                this.dataForm.goodQuantity = data.orderList.goodQuantity
                this.dataForm.aggregateAmount = data.orderList.aggregateAmount
                this.dataForm.actuallyPaid = data.orderList.actuallyPaid
                this.dataForm.createTime = data.orderList.createTime
                this.dataForm.orderStatus = data.orderList.orderStatus
                this.dataForm.payStatus = data.orderList.payStatus
                this.dataForm.shippingStatus = data.orderList.shippingStatus
                this.dataForm.receivingAForm = data.orderList.receivingAForm
                this.dataForm.remarkDesc = data.orderList.remarkDesc
                this.dataForm.logisticsInformationId = data.orderList.logisticsInformationId
                this.dataForm.logisticsInformation = data.orderList.logisticsInformation
                this.dataForm.
exemptionFromPostageStatus = data.orderList.
exemptionFromPostageStatus
                this.dataForm.a = data.orderList.a
                this.dataForm.b = data.orderList.b
                this.dataForm.c = data.orderList.c
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            axios({
              url: `${this.baseURL}/hospital_goods/orderlist/${!this.dataForm.id ? 'save' : 'update'}`,
              method: 'post',
              data: {
                'id': this.dataForm.id || undefined,
                'orderNum': this.dataForm.orderNum,
                'userId': this.dataForm.userId,
                'goodId': this.dataForm.goodId,
                'goodQuantity': this.dataForm.goodQuantity,
                'aggregateAmount': this.dataForm.aggregateAmount,
                'actuallyPaid': this.dataForm.actuallyPaid,
                'createTime': this.dataForm.createTime,
                'orderStatus': this.dataForm.orderStatus,
                'payStatus': this.dataForm.payStatus,
                'shippingStatus': this.dataForm.shippingStatus,
                'receivingAForm': this.dataForm.receivingAForm,
                'remarkDesc': this.dataForm.remarkDesc,
                'logisticsInformationId': this.dataForm.logisticsInformationId,
                'logisticsInformation': this.dataForm.logisticsInformation,
                '
exemptionFromPostageStatus': this.dataForm.
exemptionFromPostageStatus,
                'a': this.dataForm.a,
                'b': this.dataForm.b,
                'c': this.dataForm.c
              },
            // `responseType` 表示浏览器将要响应的数据类型
            // 选项包括: 'arraybuffer', 'document', 'json', 'text', 'stream'
            responseType: 'json'
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
